fix(agent-runtime): keep MCP schemas JSON-serializable - #877
Conversation
Store MCP tool input schemas as plain JSON Schema objects instead of converting them to Zod schemas before storage. Zod schemas contain circular internal references that cause JSON.stringify to fail with 'cannot serialize cyclic structures' when the agent state is serialized. The runtime now preserves the original JSON Schema and converts through ensureZodSchema only at the consumption boundary (getToolSet). Tests: 16 new tests covering schema storage, serialization roundtrip, multi-server scenarios, circular rejection defense, and full pipeline validation.
|
The actual fix here is good: The two new test files are enormous relative to the actual code change (555 lines of tests for a 2-line diff) and have a lot of redundant assertions (checking for Overall: correct root-cause identification, minimal core fix, in-scope package. Recommend porting the |
Summary
Keeps MCP tool input schemas as plain JSON Schema objects while they are stored
in the agent runtime.
Previously, MCP input schemas were converted to Zod schemas before storage.
Those Zod instances contain circular internal references and could reach a
JSON.stringify boundary, causing normal Freebuff prompts to fail with:
JSON.stringify cannot serialize cyclic structuresThe runtime now preserves the original JSON Schema and converts through
ensureZodSchemaonly at the point where schema consumption or validation isrequired.
Behavior
ensureZodSchemaingetToolSet)Verification
Note
This PR is independent from the read-only
/mcpstatus command in PR #876.